<template>
  <div class="app-container">
    <div class="filter-container">
      <el-page-header @back="backUp" class="backUp" content="企业详情"></el-page-header>
    </div>
    <div class="flex_box">
      <span class="company_name">{{company_info.name}}</span>
      <el-button class="filter-item" type="primary" icon="el-icon-plus" size='mini' @click="addPost">
        添加职位
      </el-button>
    </div>
    <el-tabs v-model="activeName" @tab-click="handleClick" class="tabs" type='card'>
      <el-tab-pane :label="item.tab" :name="item.name" v-for="(item,index) in tabs" :key='item.id'>
        <el-table
          v-if="index==0"
          :data="data"
          style="width: 100%;margin-bottom: 20px;"
          row-key="id"
          border
          default-expand-all
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        >
          <!-- <el-table-column prop="id" label="序号" align='center' width='90'/> -->
          <el-table-column label="职位名称" align='center'>
            <template slot-scope="item">
              {{getAttrValue(item.row.value_list,'POST_TYPE')}}
            </template>
          </el-table-column>
          <el-table-column prop="number_recruiters" label="招聘人数" align='center' width='120'/>
          <el-table-column prop="deliver_count" label="收到简历数"  align='center' width='100'/>
          <el-table-column prop="browse_count" label="浏览量"  align='center' width='100'/>
          <el-table-column label="来源" align='center' width='100'>
            <template slot-scope="item">
              {{getSourceText(item.row.source)}}
            </template>
          </el-table-column>
          <el-table-column prop="update_time" label="更新时间"  align='center' width='140'/>
          <el-table-column label="推广" align='center' width='200'>
            <template slot-scope="item">
              <el-switch
                v-model="item.row.is_hot"
                :active-value="1"
                :inactive-value="0"
                active-text='热门'
                style="margin-right:10px"
                @change="companyUpdate(item.row,'is_hot')"/>
                <el-switch
                v-model="item.row.is_hot"
                :active-value="1"
                :inactive-value="0"
                active-text='置顶'
                @change="companyUpdate(item.row,'is_top')"/>
            </template>
          </el-table-column>
          <el-table-column label="招聘状态" align='center' width='120'>
            <template slot-scope="item">
              <el-switch
                v-model="item.row.is_hot"
                :active-value="1"
                :inactive-value="0"
                active-text='显示'
                @change="companyUpdate(item.row,'is_show')"/>
            </template>
          </el-table-column>
          <el-table-column label="操作" align='center' width='220'>
            <template slot-scope="item">
              <el-link type="primary" class="table_btn" @click="handleDetails(item.row)" :underline="false"><i class="iconfont icon-chakan"></i>查看</el-link>
              <el-link type="primary" class="table_btn" @click="editPost(item.row)" :underline="false"><i class="iconfont icon-bianji"></i>编辑</el-link>
              <el-link type="danger" class="table_btn" @click="handleDelete(item.row.id)" :underline="false"><i class="iconfont icon-lajitong1"></i>删除</el-link>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          v-if="index==0"
          background
          class="pagination-container"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="paginate.current"
          :hide-on-single-page='isHideSingle'
          :page-sizes="paginate.sizes"
          :page-size="paginate.limit"
          :layout="paginate.layout"
          :total="paginate.total"/>
        <el-form v-if="index==1" label-width="140px" :label-position="labelPosition" >
          <el-form-item>
            <span slot='label' class="label">企业名称：</span>
            <span>{{company_info.name}}</span>
          </el-form-item>
          <el-form-item>
            <span slot='label' class="label">统一社会信用代码：</span>
            <span>{{company_info.credit_code}}</span>
          </el-form-item>
          <el-form-item>
            <span slot='label' class="label">营业执照照片：</span>
            <img :src="baseUrl+'/'+company_info.business_license" alt="" class="img">
          </el-form-item>
          <el-form-item>
            <span slot='label' class="label">审核状态：</span>
            <span>{{company_info.status==1?'审核通过':company_info.status==2?'已驳回':'审核中'}}</span>
          </el-form-item>
        </el-form>
        <el-form  v-if="index==2" label-width="140px" :label-position="labelPosition" >
          <el-form-item>
            <span slot='label' class="label">公司LOGO：</span>
            <img :src="baseUrl+'/'+company_info.company_logo" alt="" class="img">
          </el-form-item>
          <el-form-item>
            <span slot='label' class="label">工作城市：</span>
            <span>{{company_info.province_name}}{{company_info.city_name}}{{company_info.district_name}}</span>
          </el-form-item>
          <el-form-item>
            <span slot='label' class="label">工作地点：</span>
            <span>{{company_info.address}}</span>
          </el-form-item>
          <el-form-item>
            <span slot='label' class="label">公司介绍：</span>
            <span>{{company_info.desc}}</span>
          </el-form-item>
          <el-form-item v-if="company_info.company_img">
            <span slot='label' class="label">工作环境：</span>
            <div>
              <img :src="baseUrl+'/'+item" alt="" v-for="(item,index) in company_info.company_img.split(',')" :key='index' class="img">
            </div>
          </el-form-item>
          <el-form-item>
            <span slot='label' class="label">审核状态：</span>
            <span>{{company_info.status==1?'审核通过':company_info.status==2?'已驳回':'审核中'}}</span>
          </el-form-item>
        </el-form>
      </el-tab-pane>
    </el-tabs>
    <addPost ref='addPost' @success='getList'></addPost>
    <postExamine ref='postExamine'></postExamine>
  </div>
</template>

<script>
import formOperate from '@/layout/mixin/formOperate'
import postExamine from '@/views/talents/components/postExamine'
import addPost from '../components/addPost.vue'
import {companyDetails} from '@/api/talent.js'
export default {
  name: 'Index',
  mixins: [formOperate],
  data() {
    return {
      url:'/profession/admin/post',
      tabs:[
        {id:1,tab:'已发布职位',name:'first',total:0},
        {id:2,tab:'企业资质',name:'second',total:0},
        {id:3,tab:'企业加分信息',name:'third',total:0}
      ],
      activeName: 'first',// tabs默认第几个展开
      queryParam: {
        page:1,
        page_size:10,
        company_id:this.$route.query.id
      },
      company_info:'', // 企业信息
    }
  },
  mounted() {
    this.companyDetails()
    this.GetAttrData('POST_TYPE')
  },
  methods: {
    companyDetails() {
      companyDetails(this.queryParam.company_id).then(res=>{
        this.company_info = res.data
      })
    },
    // 返回
    backUp() {
      this.$router.go(-1)
    },
    // 修改置顶，热门，是否显示，审核
    companyUpdate(item,key) {
      let param = {id:item.id}
      param[key] = item[key]
      this.$http.put('/profession/admin/resume/setdata',param).then(response => {
        if (response.code === 10000) {
          this.$message.success(response.message)
          this.getList()
        } else {
          this.$message.error(response.message)
        }
      })
    },
    // 添加职位
    addPost() {
      this.$refs.addPost.show(this.postTypeList,2,this.company_info.name,this.company_info.id)
    },
    // 编辑职位
    editPost(item) {
      this.$refs.addPost.show(this.postTypeList,2,this.company_info.name,this.company_info.id,item)
    },
    // 打开职位详情弹框
    handleDetails(item) {
      this.$refs.postExamine.show(item,1)
    },
    // 关闭职位详情弹框
    handleCancel() {
      this.detailsVisible = false
    },
    // 修改置顶，热门，是否显示
    companyUpdate(item,key) {
      let param = {id:item.id}
      param[key] = item[key]
      console.log(param)
      this.$http.put('/profession/admin/resume/setdata',param).then(response => {
        if (response.code === 10000) {
          this.$message.success(response.message)
          this.getList()
        } else {
          this.$message.error(response.message)
        }
      })
    },
  },
  components:{
    addPost,
    postExamine
  }
}
</script>

<style lang="scss" scoped>
  .company_name{
    font-size: 18px;
    margin-right: 20px;
    color:#222;
  }
  .tabs{
    margin-top: 20px;
  }
  .title{
    font-size: 16px;
    margin-bottom:10px;
  }
  .info{
    line-height: 30px;
    margin-bottom:10px;
    color:#444444;
    font-size:14px;
  }
  .label{
    color:#61687C;
  }
  .img_box{
    text-align: center;
  }
  .img{
    margin:0 10px 10px 0;
    width: 150px;
  }
</style>